package com.xsystem.criteria;

import org.hibernate.criterion.Order;

public class XsystemOrder {

	public enum OrderType {
		ASC, DESC
	}
	
	private OrderType orderType;
	
	private String propertyName;
	
	private XsystemOrder(OrderType orderType, String propertyName) {
		this.orderType = orderType;
		this.propertyName = propertyName;
	}
	
	public static XsystemOrder asc(String propertyName) {
		return createOrder(OrderType.ASC, propertyName);
	}
	
	public static XsystemOrder desc(String propertyName) {
		return createOrder(OrderType.DESC, propertyName);
	}
	
	private static XsystemOrder createOrder(OrderType orderType, String propertyName) {
		return new XsystemOrder(orderType, propertyName);
	}
	
	public Order toHibernateOrder() {
		Order result = null;
		if (orderType == OrderType.ASC) {
			result = Order.asc(propertyName);
		} else if (orderType == OrderType.DESC) {
			result = Order.desc(propertyName);
		}
		return result;
	}
}
